home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_068 / mg1b / word.c < prev   
C/C++ Source or Header  |  1992-05-06  |  6KB  |  253 lines

  1. /*
  2.  *        Word mode commands.
  3.  * The routines in this file
  4.  * implement commands that work word at
  5.  * a time. There are all sorts of word mode
  6.  * commands. If I do any sentence and/or paragraph
  7.  * mode commands, they are likely to be put in
  8.  * this file.
  9.  */
  10. #include    "def.h"
  11.  
  12. /*
  13.  * Move the cursor backward by
  14.  * "n" words. All of the details of motion
  15.  * are performed by the "backchar" and "forwchar"
  16.  * routines.
  17.  */
  18. /*ARGSUSED*/
  19. backword(f, n, k) {
  20.     if (n < 0)
  21.         return (forwword(f, -n, KRANDOM));
  22.     if (backchar(FALSE, 1, KRANDOM) == FALSE)
  23.         return (FALSE);
  24.     while (n--) {
  25.         while (inword() == FALSE) {
  26.             if (backchar(FALSE, 1, KRANDOM) == FALSE)
  27.                 return TRUE;
  28.         }
  29.         while (inword() != FALSE) {
  30.             if (backchar(FALSE, 1, KRANDOM) == FALSE)
  31.                 return TRUE;
  32.         }
  33.     }
  34.     return (forwchar(FALSE, 1, KRANDOM));
  35. }
  36.  
  37. /*
  38.  * Move the cursor forward by
  39.  * the specified number of words. All of the
  40.  * motion is done by "forwchar".
  41.  */
  42. /*ARGSUSED*/
  43. forwword(f, n, k) {
  44.     if (n < 0)
  45.         return (backword(f, -n, KRANDOM));
  46.     while (n--) {
  47.         while (inword() == FALSE) {
  48.             if (forwchar(FALSE, 1, KRANDOM) == FALSE)
  49.                 return TRUE;
  50.         }
  51.         while (inword() != FALSE) {
  52.             if (forwchar(FALSE, 1, KRANDOM) == FALSE)
  53.                 return TRUE;
  54.         }
  55.     }
  56.     return (TRUE);
  57. }
  58.  
  59. /*
  60.  * Move the cursor forward by
  61.  * the specified number of words. As you move,
  62.  * convert any characters to upper case.
  63.  */
  64. /*ARGSUSED*/
  65. upperword(f, n, k) {
  66.     register int    c;
  67.  
  68.     if (n < 0)
  69.         return (FALSE);
  70.     while (n--) {
  71.         while (inword() == FALSE) {
  72.             if (forwchar(FALSE, 1, KRANDOM) == FALSE)
  73.                 return TRUE;
  74.         }
  75.         while (inword() != FALSE) {
  76.             c = lgetc(curwp->w_dotp, curwp->w_doto);
  77.             if (ISLOWER(c) != FALSE) {
  78.                 c = TOUPPER(c);
  79.                 lputc(curwp->w_dotp, curwp->w_doto, c);
  80.                 lchange(WFHARD);
  81.             }
  82.             if (forwchar(FALSE, 1, KRANDOM) == FALSE)
  83.                 return TRUE;
  84.         }
  85.     }
  86.     return (TRUE);
  87. }
  88.  
  89. /*
  90.  * Move the cursor forward by
  91.  * the specified number of words. As you move
  92.  * convert characters to lower case.
  93.  */
  94. /*ARGSUSED*/
  95. lowerword(f, n, k) {
  96.     register int    c;
  97.  
  98.     if (n < 0)
  99.         return (FALSE);
  100.     while (n--) {
  101.         while (inword() == FALSE) {
  102.             if (forwchar(FALSE, 1, KRANDOM) == FALSE)
  103.                 return TRUE;
  104.         }
  105.         while (inword() != FALSE) {
  106.             c = lgetc(curwp->w_dotp, curwp->w_doto);
  107.             if (ISUPPER(c) != FALSE) {
  108.                 c = TOLOWER(c);
  109.                 lputc(curwp->w_dotp, curwp->w_doto, c);
  110.                 lchange(WFHARD);
  111.             }
  112.             if (forwchar(FALSE, 1, KRANDOM) == FALSE)
  113.                 return TRUE;
  114.         }
  115.     }
  116.     return (TRUE);
  117. }
  118.  
  119. /*
  120.  * Move the cursor forward by
  121.  * the specified number of words. As you move
  122.  * convert the first character of the word to upper
  123.  * case, and subsequent characters to lower case. Error
  124.  * if you try and move past the end of the buffer.
  125.  */
  126. /*ARGSUSED*/
  127. capword(f, n, k) {
  128.     register int    c;
  129.  
  130.     if (n < 0)
  131.         return (FALSE);
  132.     while (n--) {
  133.         while (inword() == FALSE) {
  134.             if (forwchar(FALSE, 1, KRANDOM) == FALSE)
  135.                 return TRUE;
  136.         }
  137.         if (inword() != FALSE) {
  138.             c = lgetc(curwp->w_dotp, curwp->w_doto);
  139.             if (ISLOWER(c) != FALSE) {
  140.                 c = TOUPPER(c);
  141.                 lputc(curwp->w_dotp, curwp->w_doto, c);
  142.                 lchange(WFHARD);
  143.             }
  144.             if (forwchar(FALSE, 1, KRANDOM) == FALSE)
  145.                 return TRUE;
  146.             while (inword() != FALSE) {
  147.                 c = lgetc(curwp->w_dotp, curwp->w_doto);
  148.                 if (ISUPPER(c) != FALSE) {
  149.                     c = TOLOWER(c);
  150.                     lputc(curwp->w_dotp, curwp->w_doto, c);
  151.                     lchange(WFHARD);
  152.                 }
  153.                 if (forwchar(FALSE, 1, KRANDOM) == FALSE)
  154.                     return TRUE;
  155.             }
  156.         }
  157.     }
  158.     return (TRUE);
  159. }
  160.  
  161. /*
  162.  * Kill forward by "n" words.
  163.  */
  164. /*ARGSUSED*/
  165. delfword(f, n, k) {
  166.     register RSIZE    size;
  167.     register LINE    *dotp;
  168.     register int    doto;
  169.  
  170.     if (n < 0)
  171.         return (FALSE);
  172.     if ((lastflag&CFKILL) == 0)        /* Purge kill buffer.    */
  173.         kdelete();
  174.     thisflag |= CFKILL;
  175.     dotp = curwp->w_dotp;
  176.     doto = curwp->w_doto;
  177.     size = 0;
  178.     while (n--) {
  179.         while (inword() == FALSE) {
  180.             if (forwchar(FALSE, 1, KRANDOM) == FALSE)
  181.                 goto out;    /* Hit end of buffer.    */
  182.             ++size;
  183.         }
  184.         while (inword() != FALSE) {
  185.             if (forwchar(FALSE, 1, KRANDOM) == FALSE)
  186.                 goto out;    /* Hit end of buffer.    */
  187.             ++size;
  188.         }
  189.     }
  190. out:
  191.     curwp->w_dotp = dotp;
  192.     curwp->w_doto = doto;
  193.     return (ldelete(size, KFORW));
  194. }
  195.  
  196. /*
  197.  * Kill backwards by "n" words. The rules
  198.  * for success and failure are now different, to prevent
  199.  * strange behavior at the start of the buffer. The command
  200.  * only fails if something goes wrong with the actual delete
  201.  * of the characters. It is successful even if no characters
  202.  * are deleted, or if you say delete 5 words, and there are
  203.  * only 4 words left. I considered making the first call
  204.  * to "backchar" special, but decided that that would just
  205.  * be wierd. Normally this is bound to "M-Rubout" and
  206.  * to "M-Backspace".
  207.  */
  208. /*ARGSUSED*/
  209. delbword(f, n, k) {
  210.     register RSIZE    size;
  211.  
  212.     if (n < 0)
  213.         return (FALSE);
  214.     if ((lastflag&CFKILL) == 0)        /* Purge kill buffer.    */
  215.         kdelete();
  216.     thisflag |= CFKILL;
  217.     if (backchar(FALSE, 1, KRANDOM) == FALSE)
  218.         return (TRUE);            /* Hit buffer start.    */
  219.     size = 1;                /* One deleted.        */
  220.     while (n--) {
  221.         while (inword() == FALSE) {
  222.             if (backchar(FALSE, 1, KRANDOM) == FALSE)
  223.                 goto out;    /* Hit buffer start.    */
  224.             ++size;
  225.         }
  226.         while (inword() != FALSE) {
  227.             if (backchar(FALSE, 1, KRANDOM) == FALSE)
  228.                 goto out;    /* Hit buffer start.    */
  229.             ++size;
  230.         }
  231.     }
  232.     if (forwchar(FALSE, 1, KRANDOM) == FALSE)
  233.         return (FALSE);
  234.     --size;                    /* Undo assumed delete.    */
  235. out:
  236.     return (ldelete(size, KBACK));
  237. }
  238.  
  239. /*
  240.  * Return TRUE if the character at dot
  241.  * is a character that is considered to be
  242.  * part of a word. The word character list is hard
  243.  * coded. Should be setable.
  244.  */
  245. inword() {
  246.     if (curwp->w_doto == llength(curwp->w_dotp))
  247.         return (FALSE);
  248.     if (ISWORD(lgetc(curwp->w_dotp, curwp->w_doto)) != FALSE)
  249.         return (TRUE);
  250.     return (FALSE);
  251. }
  252.  
  253.